package com.ys.peony.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ys.peony.R;
import com.ys.peony.interfaces.MyItemClickListener;
import com.ys.peony.model.BusiFileModel;
import com.ys.peony.utils.ImageLoadUtils;
import com.ys.peony.utils.PixelUtils;

import java.util.List;


/**
 * Created by Administrator on 2017/3/17.
 */

public class ClientPicItemAdapter extends RecyclerView.Adapter {

    List<BusiFileModel> mList;
    Context mContext;
    MyItemClickListener.ClientItemListener mListener;
    String name = "";
    int position;
    public ClientPicItemAdapter(List<BusiFileModel> list,String name, Context context, MyItemClickListener.ClientItemListener listeneristener,int position) {
        mList = list;
        mContext = context;
        mListener = listeneristener;
        this.name = name;
        this.position = position;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.pic_item_layout,null);
        return new ItemViewHolder(view, mListener,position);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((ItemViewHolder) holder).setData(name,mList.get(position).getFilePath(),mList.get(position).getId());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {

        private RelativeLayout one_rl;
        private TextView one_tv;
        private ImageView one_img;
        private MyItemClickListener.ClientItemListener mListener;
        private String mImgUrl;
        private long mId;
        private int parentPosition;
        public ItemViewHolder(View itemView, MyItemClickListener.ClientItemListener listener,int parentPosition) {
            super(itemView);
            one_rl = (RelativeLayout) itemView.findViewById(R.id.one_rl);
            one_tv = (TextView) itemView.findViewById(R.id.one_tv);
            one_img = (ImageView) itemView.findViewById(R.id.one_img);
            one_rl.setOnClickListener(this);
            one_rl.setOnLongClickListener(this);
            mListener = listener;
            this.parentPosition = parentPosition;
        }

        public void setData(String name,String imgPath,long id) {
            mImgUrl = imgPath;
            one_tv.setText(name);
            mId = id;
            ImageLoadUtils.showImg(one_img, imgPath, false);
        }

        @Override
        public void onClick(View view) {
            mListener.onImgClick(mImgUrl);
        }

        @Override
        public boolean onLongClick(View view) {
            mListener.onImgLongClick(mId,parentPosition,getPosition());
            return false;
        }
    }
}
